
<link rel="stylesheet" href="jquery/easyui/themes/default/easyui.css">
<link rel="stylesheet" href="jquery/easyui/themes/icon.css">
 <link rel="stylesheet" href="dropzonefileupload/dropzone.css" >
<body>	
<a href="javascript:addMaterialType()" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'">添加物料</a>
<div style="height:80%">
    <table id="easyui_datagrid_select_temp" style="border:1px solid blue" >

    </table>
</div>
<div id="dlg" class="easyui-dialog" style="width:300px" closed="true" buttons="#dlg-buttons">
    <form id="fm" method="post" novalidate style="margin:0;padding:20px 50px">
        <!-- <div style="margin-bottom:20px;font-size:14px;border-bottom:1px solid #ccc">User Information</div> -->
        <div style="margin-bottom:10px">
            <select class="easyui-combobox" name="type" required label="物料仓位" style="width:100%">
                <option value="3">信息备注仓</option>
            </select>
        </div>
        <div style="margin-bottom:10px;display: none">
            <input name="id" class="easyui-textbox" label="编号:" style="width:100%">
        </div>
        <div style="margin-bottom:10px">
            <input name="materialType" class="easyui-textbox" required label="物料类型:" style="width:100%">
        </div>
        <div style="margin-bottom:10px">
            <select class="easyui-combobox" name="status" required label="状态" style="width:100%">
                <option value="1">启用</option>
                <option value="0">禁用</option>
            </select>
        </div>
    </form>
</div>
<div id="dlg-buttons">
    <a id="save_material_type"   href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveMaterialAjax()" style="width:60px">保存</a>
    <a id="upload_material_type" href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="uploadMaterialAjax()" style="width:60px">更新</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:60px">取消</a>
</div>
<script src="https://upload.shinehao.com.cn/20180816150739jquery-1.8.3.min.js"></script>
<script src="https://upload.shinehao.com.cn/20180816145716jquery.easyui.min.js"></script>
<script src="https://upload.shinehao.com.cn/20180816151727easyui-lang-zh_CN.js"></script>

<script>

$(function(){
    /* $("body").bind("click",function(){
        $('#easyui_datagrid_select_temp').combogrid("showPanel");
    }) */
    
    
    $('#easyui_datagrid_select_temp').combogrid({
        mode:"remote",
        url:window.parent.serverUrl+"/materialTypeExceptSource/getList",
        queryParams: {
            
        },
        idField: 'id',
        textField: 'materialType',
        columns:[[
            {field:'id',title:'id'},
            {field:'materialType',title:'物料类型',align:"center"},
            {field:'type',title:'仓位',align:"center",formatter: function(value,row,index){
				if(value==-1){
					return '固定仓';
				}
				if(value==1){
					return '原材料仓';
				}
				if(value==2){
					return '辅料仓';
				}
				if(value==3){
					return '信息备注仓';
				}
			}},
            {field:'status',title:'状态',align:"center",formatter: function(value,row,index){
				if(value==1){
					return '<span style="green">启用</span>';
				}
				if(value==0){
					return '<span color="red">禁用</span>';
				}
			}}
        ]],
        height:"10%",
        width:"50%",
        panelWidth:"100%",
        panelHeight:"80%",
        //rownumbers:true,
        //fitColumns:true,
        pagination:false,
        loadMsg:"加载中,请等待...",
        singleSelect:true,
        align:"center",
        //toolbar: '#easyui_datagrid_source_fac_tool',
        loadFilter: function(data){
          return data.data;  
        },
        keyHandler: {
            enter: function(e){
            },
            query: function (q) {
                $('#easyui_datagrid_select_temp').combogrid("grid").datagrid("reload", {
                    'materialType': q,
                    'type':3
                });
                $('#easyui_datagrid_select_temp').combogrid("setValue",q);
            },
            up: function (e) {
                
            },
            down: function (e) {
                
            }
        },
        onLoadSuccess:function(data){
            if(data.total > 0) {
                $("input[type='text']").focus();
                return;
            }  
            //$(this).datagrid('appendRow', { color: '<div style="text-align:center;color:red">没有相关记录！</div>' }).datagrid('mergeCells', { index: 0, field: 'color', colspan: 3});  
            $("input[type='text']").focus();
            $('#easyui_datagrid_select_temp').combogrid("showPanel");
        },
        /*onSelect:function(index,row){
            console.info(row);
            var self = $(window.parent.document).find("["+dom.split(":")[0]+"='"+dom.split(":")[1]+"']");
            //console.info("myid:"+$(self).attr("myid")+":"+$(self).length+":"+"'"+dom.split(":")[0]+"'");
            //console.info("id:"+$(self).attr("id")+":"+$(self).length+":"+"'"+dom.split(":")[0]+"'");
            //console.info($(self).attr("'"+dom.split(":")[0]+"'"));
            //物料代码 色号 颜色描述 规格 填充
            
            $("input[type='text']").focus();
            $('#easyui_datagrid_source_fac').combogrid("showPanel");
        },*/
        onClickRow:function(index,row){
        	editMaterialType();
        }
    });
    $('#easyui_datagrid_select_temp').combogrid("showPanel");
    $("input[type='text']").focus();
    
    $("#dlg").dialog({  
        onClose: function () {  
            $('#easyui_datagrid_select_temp').combogrid("showPanel"); 
        }  
    });
})


</script>
<script type="text/javascript">
function addMaterialType(){
	$('#easyui_datagrid_select_temp').combogrid("hidePanel");
	$('#dlg').dialog('open').dialog('center').dialog('setTitle','添加');
	$("#upload_material_type").hide();
	$("#save_material_type").show();
	$('#fm').form('clear');
}
function editMaterialType(){
	$('#easyui_datagrid_select_temp').combogrid("hidePanel");
    var row = $('#easyui_datagrid_select_temp').combogrid('grid').datagrid('getSelected');
    if (row){
        $('#dlg').dialog('open').dialog('center').dialog('setTitle','编辑'+row.materialType);
        $("#upload_material_type").show();
        $("#save_material_type").hide();
        $('#fm').form('clear');
        $('#fm').form('load',row);
    }
}
function saveMaterialAjax(){
    $.messager.progress();
    $.ajax({
        type: 'POST',
        url: window.parent.serverUrl+"/materialTypeExceptSource/insertMaterialType",
        data: {type:$("[name='type']").val(),materialType:$("[name='materialType']").val(),status:$("[name='status']").val()},
        success: function(data){
          $.messager.progress('close');
          alert("操作成功");
          $('#dlg').dialog('close');        // close the dialog
          $('#easyui_datagrid_select_temp').combogrid("grid").datagrid("reload");
          $('#easyui_datagrid_select_temp').combogrid("showPanel");
        }
	});
}
function uploadMaterialAjax(){
	$.messager.progress();
    $('#fm').form('submit',{
        url: window.parent.serverUrl+"/materialTypeExceptSource/updateMaterialType",
        onSubmit: function(){
            return $(this).form('validate');
        },
        success: function(result){
            $.messager.progress('close');
            alert("操作成功");
            $('#dlg').dialog('close');        // close the dialog
            $('#easyui_datagrid_select_temp').combogrid("grid").datagrid("reload");
            $('#easyui_datagrid_select_temp').combogrid("showPanel");
        }
    });
}
</script>
</body>


























